namespace FIREFLYX {
    /**画一条线 */
    export class DrawLine implements IExample {
        public Init(canvas: HTMLCanvasElement): void {
            let gl = canvas.getContext("webgl2");
            let vs = `#version 300 es
            layout (location = 0) in vec4 a_Position;
            void main() {
                gl_Position = a_Position;
                gl_PointSize = 20.0;
            }
            `;

            let fs = `#version 300 es
                precision highp float;
                out vec4 color;
                void main(){
                    color = vec4(1.0,0.0,0.0,1.0);
                }
            `;

            //init Shaders
            let sp = InitShader(gl, vs, fs);
            //使用 gl 程序
            gl.useProgram(sp);

            //set of variables
            const data = new Float32Array(
                [0.5, 0, 0,
                    0, 0, 0,
                    0, 0.5, 0,
                    -0.5, 0.5, 0,
                ]
            );
            const pLen = data.length / 3;

            //顶点数据buffer
            const vbo = gl.createBuffer();
            gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
            gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
            //数据不够时会填充默认值
            gl.vertexAttribPointer(AttributeLayout.POSITION, 3, gl.FLOAT, false, 0, 0);
            //连接启用  分配个 变量的 缓冲区对象
            gl.enableVertexAttribArray(AttributeLayout.POSITION);

            //绘制提交
            gl.drawArrays(gl.POINTS, 0, pLen);
            // gl.drawArrays(gl.LINES, 0, pLen);
            gl.drawArrays(gl.LINE_LOOP, 0, pLen);
            console.log(`LINE_WIDTH ${gl.getParameter(gl.LINE_WIDTH)}`);
        }

    }
}